package org.micode.demo.db.domain.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.micode.common.validater.InsertGroup;
import org.micode.common.validater.UpdateGroup;
import org.micode.common.validater.EnumValidation;
import org.micode.common.exception.VerifyFailException;
import org.micode.common.utils.StringExtUtils;
import org.micode.common.domain.base.entity.BaseNormalEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 角色菜单权限实体类
 *
 * @author: wutianbin
 * @version: v1.0.27
 * @CreateDate: 2021-11-10
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SysRoleMenuDO extends BaseNormalEntity<Long> {

    /** ID，Long */
    @NotNull(message = "ID,不能为空", groups = UpdateGroup.class)
    @PositiveOrZero(message = "ID,不能为负数", groups = {InsertGroup.class, UpdateGroup.class})
    private Long id;

    /** 角色ID，Long */
    @NotNull(message = "角色ID,不能为空", groups = InsertGroup.class)
    @PositiveOrZero(message = "角色ID,不能为负数", groups = {InsertGroup.class, UpdateGroup.class})
    private Long roleId;

    /** 菜单ID，Long */
    @NotNull(message = "菜单ID,不能为空", groups = InsertGroup.class)
    @PositiveOrZero(message = "菜单ID,不能为负数", groups = {InsertGroup.class, UpdateGroup.class})
    private Long menuId;

    @JsonIgnore
    @Override
    public Long getKeyValue() {
        return id;
    }

    @Override
    public void checkBeforeInsert() {
        if (null == roleId) {
            throw new VerifyFailException("SysRoleMenuDO.roleId 必须非空");
        }
        if (null == menuId) {
            throw new VerifyFailException("SysRoleMenuDO.menuId 必须非空");
        }
    }

    @Override
    public String toString() {
        return "id=" + id +
                ", roleId=" + roleId +
                ", menuId=" + menuId +
                ", " + super.toString();
    }

}
